package com.ea.modular.controller.sys;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ea.common.annotation.LogAnnotation;
import com.ea.common.parent.controller.BaseController;

import io.swagger.annotations.ApiOperation;

import com.ea.modular.service.sys.NoticeService;
import com.ea.modular.model.sys.Notice;


/**
 * NoticeController控制器
 * @author jun
 *
 */
@Controller
@RequestMapping(value="/notice")
public class NoticeController extends BaseController {

	@Autowired
	private NoticeService noticeService;

	private String PREFIX = "/system/notice/";
	/**
	 * 跳转到主页
	 * @return
	 */
	@ApiOperation(value = "首页")
	@RequestMapping(value = "",method=RequestMethod.GET)
	public String home() {		 
		return PREFIX + "notice";
	}

	/**
	 * 列表
	 * @param Notice
	 * @return
	 */
	@LogAnnotation
	@ApiOperation(value = "列表")
	@RequestMapping(value = "/list",method=RequestMethod.POST)
	@ResponseBody
	public Object list(Notice notice){
		return noticeService.findPage(notice);
	}

	/**
	 * 删除
	 * @return
	 */
	@LogAnnotation
	@ApiOperation(value = "删除")
	@RequestMapping(value = "/delete",method=RequestMethod.POST)
	@ResponseBody
	public int delete(String id) {
		return noticeService.delete(id);
	}


	/**
	 * 详情页
	 * @return
	 */
	@ApiOperation(value = "详情")
	@RequestMapping(value = "/form",method=RequestMethod.GET)
	public String form(Model model,String id,String type) {

		//判断是否为修改页
		if(type.equals("update")) {
			Notice notice = new Notice();
			notice.setId(id);
			notice = noticeService.get(notice);

			model.addAttribute("notice",notice);
			//跳转修改页
			return PREFIX + "notice_edit";
		}

		//跳转添加页
		return PREFIX + "notice_add";
	}

	/**
	 * 管理
	 * @return
	 */
	@LogAnnotation
	@ApiOperation(value = "编辑")
	@RequestMapping(value = "/save",method=RequestMethod.POST)
	@ResponseBody
	public int save(Notice notice,String type) {
		//判断是否为修改
		if(type.equals("update")) {
			return noticeService.update(notice);
		}

		return noticeService.insert(notice);
	}

	/**
	 * 详情
	 * @return
	 */
	@ApiOperation(value = "详情")
	@RequestMapping(value = "/detail",method=RequestMethod.GET)
	public String detail(Model model,String id) {

		Notice notice = new Notice();
		notice.setId(id);
		notice = noticeService.get(notice);

		model.addAttribute("notice",notice);
		//跳转详情页
		return PREFIX + "notice_detail";
	}




}
